package com.lw.mybatis.mapper;

import com.lw.mybatis.pojo.TbUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/3 11:29
 */
public interface UserMapper {
    List<TbUser> findById(@Param("ids") List<Long> ids);
    List<TbUser> findAll();

    @Select("select * from tb_user")
    List<TbUser> findAll2();

    @Select("select * from tb_user where id=#{id}")
    TbUser findById2(Long id);


    int updateById(TbUser user);

    @Update("<script>update tb_user\n" +
            "        <set>\n" +
            "            <if test=\"username !=null and username !=''\">\n" +
            "                username=#{username},\n" +
            "            </if>\n" +
            "            <if test=\"password !=null and password !=''\">\n" +
            "                password=#{password},\n" +
            "            </if>\n" +
            "            <if test=\"email !=null and email !=''\">\n" +
            "                email=#{email},\n" +
            "            </if>\n" +
            "            <if test=\"gender !=null and gender !=''\">\n" +
            "                gender=#{gender},\n" +
            "            </if>\n" +
            "            <if test=\"flag !=null \">\n" +
            "                flag=#{flag},\n" +
            "            </if>\n" +
            "            <if test=\"role !=null\">\n" +
            "                role=#{role},\n" +
            "            </if>\n" +
            "            <if test=\"code !=null and code !=''\">\n" +
            "                code=#{code},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "             where id=#{id}</script>")
    int updateById2(TbUser user);


}
